Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

video-worker

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

video-worker

API wrapper for Youtube, Vimeo and Self-Hosted videos

  • 1.1.17
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.3K
increased by5.77%
Maintainers
1
Weekly downloads
 
Created
Source

Video Worker

API wrapper for Youtube, Vimeo and Local videos

Getting Started

HTML

<!-- Video Worker -->
<script src="video-worker/dist/video-worker.min.js"></script>

Or use NPM

npm: npm install video-worker --save

Simple Example

import VideoWorker from 'video-worker';

const videoObject = new VideoWorker('https://www.youtube.com/watch?v=ab0TSkLe-E0');

if (videoObject.isValid()) {
    // retrieve iframe/video dom element.
    videoObject.getVideo((video) => {
        const $parent = video.parentNode;

        // insert video in the body.
        document.body.appendChild(video);

        // remove temporary parent video element (created by VideoWorker).
        $parent.parentNode.removeChild($parent);
    });
}

Video URLs examples:

  • YouTube https://www.youtube.com/watch?v=ab0TSkLe-E0
  • Vimeo https://vimeo.com/110138539
  • Local Hosted mp4:./local-video.mp4,webm:./local-video.webm,ogv:./local-video.ogv

Note: for self-hosted videos required only 1 video type, not necessary use all mp4, webm and ogv. This need only for maximum compatibility with all browsers.

Options

NameTypeDefaultDescription
autoplayboolfalseVideo autoplay.
loopboolfalseVideo playing loop.
showControlsbooltrueVideo controls.
accessibilityHiddenboolfalseAdd accessibility attributes for videos used on backgrounds.
muteboolfalseMute sound.
volumeint100Volume level from 0 to 100.
startTimefloat0Start time in seconds when video will be started (this value will be applied also after loop).
endTimefloat0End time in seconds when video will be ended.

Example

new VideoWorker('<URL_TO_YOUR_VIDEO>', {
    autoplay: true,
    loop: true,
    startTime: 10,
});

Events

NameParametersDescription
readyeventFires only once, when the video is ready to play.
volumechangeeventFires when video volume changed.
timeupdateeventFires when video current time changed.
startedeventFires only once, when the video is started playing.
playeventFires on video play start.
pauseeventFires on video paused.
endedeventFires on video ended.
errorerrorFires on video error

Example

videoObject.on('ready', (event) => {
    console.log('video ready', event);
});

Methods

NameResultDescription
isValidboolCheck if the video is successfully determined and ready to use.
play-Play video.
pause-Pause video.
mute-Mute sound.
unmute-Unmute sound.
getMutedintGet mute state. videoObject.getMuted((muted) => { ... })
setVolume-Set volume level (takes integer value from 0 to 100). videoObject.setVolume(40);
getVolumeintGet volume level. videoObject.getVolume((volume) => { ... })
getImageURLstringRetrieves Youtube/Vimeo video poster image URL. videoObject.getImageURL((url) => { ... })
getVideodomRetrieves iframe/video dom element. videoObject.getVideo((video) => { ... })

Example

videoObject.mute();

For Developers

Installation

  • Run npm install in the command line. Or if you need to update some dependencies, run npm update

Building

  • npm run build to run build

Linting

  • npm run js-lint to show eslint errors
  • npm run js-lint-fix to automatically fix some of the eslint errors

Keywords

FAQs

Package last updated on 09 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc